<template>
  <el-dialog title="物资绑定信息" :visible.sync="open" width="70%" :close-on-click-modal="false">
    <el-table v-loading="loading" :data="tableData" border>
      <el-table-column label="序号" align="center" prop="index" width="70">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="siteId" align="center" label="站址编码" />
      <el-table-column prop="osDetailId" align="center" label="出库明细ID" />
      <el-table-column prop="categoryCode" align="center" label="物资编码" />
      <el-table-column prop="categoryName" align="center" label="物资名称" />
      <el-table-column prop="amount" align="center" label="物资已绑定数量" />
      <el-table-column prop="subAmount" align="center" label="建设子专业已绑定数量" />
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            v-if="form.pageType === 'edit' && scope.row.subspecStatus === '0'"
            type="text"
            @click="openSubSpecDetail(scope.row)"
          >编辑</el-button>
          <p v-else-if="scope.row.amount === '0'">无需绑定</p>
          <el-button v-else type="text" @click="openSubSpecDetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button class="pms-button-primary" @click="handleSend">确认绑定结果</el-button>
      <el-button class="pms-button-primary" @click="open = false ">关闭</el-button>
    </span>
    <SubSpecBunding ref="subSpecBunding" @getList="getList" />
  </el-dialog>
</template>

<script>
import SubSpecBunding from './subSpecBunding'
// import * as Axios from '@/api/settlement'

export default {
  name: 'ProductBunding',
  components: { SubSpecBunding },
  data() {
    return {
      open: false,
      form: {},
      loading: false,
      tableData: []
    }
  },
  methods: {
    productBundingOpen(val) {
      this.form = val
      this.open = true
      this.getList()
    },
    async getList() {
      // const obj = {
      //   prjId: this.form.prjId
      // }
      // this.loading = true
      // const { data } = await Axios.queryProductBundingInfos(obj)
      // this.tableData = data
      // this.loading = false
    },
    // 建设子专业详情页
    openSubSpecDetail(row) {
      var pageType = this.form.pageType
      if (pageType === 'edit' && row.subspecStatus === '0') {
        pageType = 'edit'
      } else {
        pageType = 'view'
      }
      var bundingId = row.bundingId	// 绑定流水号
      var materialCode = row.categoryCode	// 物资编码
      var amount = row.amount	// 绑定数量
      var title = row.categoryName + '(' + row.categoryCode + ')建设子专业绑定信息'
      const obj = {
        bundingId,
        materialCode,
        amount,
        pageType,
        title
      }
      this.$refs['subSpecBunding'].handleOpen(obj)
    },
    async handleSend() {
      // const obj = {
      //   prjId: this.form.prjId
      // }
      // const res = await Axios.updateSubSpecStatus(obj)
      // if (res.code !== '200') {
      //   return
      // }
      // this.$message.success(res.message)
      // this.open = false
    }

  }
}
</script>

<style scoped>
::v-deep .dialog-footer {
  display: flex;
  justify-content: center;
}
</style>
